<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jQueryZ中的AJAX</title>
    <link crossorigin="anonymous"  href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap-theme.css" rel="stylesheet">
    <script crossorigin="anonymous" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
    <div class="container">
        <h2>jQuery发送AJAX请求</h2>
        <button class="btn btn-primary">GET</button>
        <button class="btn btn-danger">POST</button>
        <button class="btn btn-info">通用的AJAX请求</button>
    </div>
    <script>
        $('button').eq(0).click(function(){
            $.get('http://localhost:8000/jquery-server', {a:100, b: 150}, function(data){
                console.log(data)
            }, 'json')
        })

        $('button').eq(1).click(function(){
            $.post('http://localhost:8000/jquery-server', {c:100, d: 150}, function(data){
                console.log(data)
            })
        })

        $('button').eq(2).click(function(){
            console.log('test');
            $.ajax({
                url: 'http://localhost:8000/jquery-server',
                type: 'GET',
                data: {
                    a: 130,
                    b: 200
                },
                dataType: 'json',
                timeout: 2000,
                success: function(data){
                    console.log(data);
                },
                error: function(){
                    console.log("出错了！")
                }
            });
        });
    </script>
</body>
</html>